<html>
<head>
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="canonical" href="./Demultiplexer_Binary.html">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Connects the `word_in` input port to one of the words in the `words_out` output port, as selected by the `selector` binary address, and raises the corresponding valid bit in the `valids_out` output port.  *If the `selector` value is greater than the number of output words specified by the `OUTPUT_COUNT` parameter, then none of the `valids_out` bits will be set.*">
<title>Demultiplexer Binary</title>
</head>
<body>

<p class="inline bordered"><b><a href="./Demultiplexer_Binary.v">Source</a></b></p>
<p class="inline bordered"><b><a href="./legal.html">License</a></b></p>
<p class="inline bordered"><b><a href="./index.html">Index</a></b></p>

<h1>Binary Demultiplexer</h1>
<p>Connects the <code>word_in</code> input port to one of the words in the <code>words_out</code>
 output port, as selected by the <code>selector</code> binary address, and raises the
 corresponding valid bit in the <code>valids_out</code> output port.  <em>If the
 <code>selector</code> value is greater than the number of output words specified by
 the <code>OUTPUT_COUNT</code> parameter, then none of the <code>valids_out</code> bits will be
 set.</em></p>
<h2>Implementation Options</h2>
<p>Set the <code>BROADCAST</code> parameter to 1 to simply replicate and connect
 <code>word_in</code> to each word in <code>words_out</code>, without any logic. The valid bit
 will indicate which downstream logic should accept the data, and other
 logic can snoop the data if that's part of your larger design.</p>
<p>Set the <code>BROADCAST</code> parameter to 0 to send <code>word_in</code> to <em>only</em> the selected
 word in <code>words_out</code>, whose valid bit is set. All other output words are
 annulled to zero. If no valid bit is set, all output words stay at zero.</p>
<p>Not broadcasting the input to the output costs some logic, but less than it
 appears from a standalone synthesis of the demultiplexer: the inferred
 <a href="./Annuller.html">Annullers</a> will very likely disappear into downstream LUT
 logic, it also makes tracing a simulation easier, and adds some design
 security and robustness since unselected downstream logic cannot snoop or
 accidentally receive other data.</p>
<p>If necessary, select the Annuller <code>IMPLEMENTATION</code> which yields the best
 logic synthesis. Usually, this does not matter, and can be set to "AND".</p>
<p>Setting <code>BROADCAST</code> to any value other than 1 or 0 will disconnect
 <code>word_in</code> from <code>words_out</code>, raise some critical warnings in your CAD tool,
 and generally cause a lot of downstream logic to optimize away, so you
 should notice...</p>

<pre>
`default_nettype none

module <a href="./Demultiplexer_Binary.html">Demultiplexer_Binary</a>
#(
    parameter       BROADCAST           = 0,
    parameter       WORD_WIDTH          = 0,
    parameter       ADDR_WIDTH          = 0,
    parameter       OUTPUT_COUNT        = 0,
    parameter       IMPLEMENTATION      = "AND",

    // Do not set at instantiation
    parameter   TOTAL_WIDTH = WORD_WIDTH * OUTPUT_COUNT
)
(
    input   wire    [ADDR_WIDTH-1:0]    selector,
    input   wire    [WORD_WIDTH-1:0]    word_in,
    output  wire    [TOTAL_WIDTH-1:0]   words_out,
    output  wire    [OUTPUT_COUNT-1:0]  valids_out
);
</pre>

<p>Convert the binary <code>selector</code> to a single one-hot bit vector
 which signals which output port will receive the input word.</p>

<pre>
    wire [OUTPUT_COUNT-1:0] selector_one_hot;

    <a href="./Binary_to_One_Hot.html">Binary_to_One_Hot</a>
    #(
        .BINARY_WIDTH   (ADDR_WIDTH),
        .OUTPUT_WIDTH   (OUTPUT_COUNT)
    )
    valid_out
    (
        .binary_in      (selector),
        .one_hot_out    (selector_one_hot)
    );
</pre>

<p>Then use that one-hot selector to steer the input to a particular output.</p>

<pre>
    <a href="./Demultiplexer_One_Hot.html">Demultiplexer_One_Hot</a>
    #(
        .BROADCAST      (BROADCAST),
        .WORD_WIDTH     (WORD_WIDTH),
        .OUTPUT_COUNT   (OUTPUT_COUNT),
        .IMPLEMENTATION (IMPLEMENTATION)
    )
    word_in_demux
    (
        .selectors      (selector_one_hot),
        .word_in        (word_in),
        .words_out      (words_out),
        .valids_out     (valids_out)
    );

endmodule
</pre>

<hr>
<p><a href="./index.html">Back to FPGA Design Elements</a>
<center><a href="https://fpgacpu.ca/">fpgacpu.ca</a></center>
</body>
</html>

